package product.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import product.dto.SportsDto;
import product.mapper.SportsMapper;
import product.params.SportsAddParam;
import product.params.SportsSearchParam;
import product.service.SportsServiceI;
import user.dto.UserDto;
import user.service.UserServiceI;

import java.text.SimpleDateFormat;
import java.util.List;
@AllArgsConstructor
@DubboService(version = "1.0.0")
public class SportsServiceImpl implements SportsServiceI {

    private SportsMapper sportsMapper;

    @DubboReference(version = "1.0.0")
    private UserServiceI userServiceI;
    @Override
    public List<SportsDto> searchSports(SportsSearchParam param) {
        return List.of();
    }

    @Override
    public void addSports(SportsAddParam param) {
        SportsDto sportsDto = new SportsDto();
        sportsDto.setUsername(param.getUsername());
        UserDto userDto = userServiceI.getUserByName(param.getUsername());
        sportsDto.setLastWorkoutDate(param.getLastWorkoutDate());
        sportsDto.setUserId(userDto.getUserId());
        sportsDto.setTotalWorkouts(param.getTotalWorkouts());
        sportsDto.setTotalCaloriesBurned(param.getTotalWorkouts()*param.getExerciseType().getCaloriesPerHour());
        sportsMapper.insertSports(sportsDto);




    }
}
